<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
</head>
<body>


<div class="modal fade" id="changePasswordModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">修改密码</h5>
                <button type="button" class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form id="changePasswordForm">
                    <div class="form-group">
                        <label>原密码</label>
                        <input type="password" class="form-control" name="oldPassword" required>
                    </div>
                    <div class="form-group">
                        <label>新密码</label>
                        <input type="password" class="form-control" name="newPassword" required>
                    </div>
                    <div class="form-group">
                        <label>确认密码</label>
                        <input type="password" class="form-control" name="confirmPassword" required>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="submitChangePassword">确认修改</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(
        function(
        ) {
            // 点击提交按钮
            $(
                "#submitChangePassword").click(function(
            ) {
                let formData = $("#changePasswordForm").serializeObject
                ();

                $.
                ajax
                ({
                    url: "/password/change"
                    ,
                    type: "POST"
                    ,
                    contentType: "application/json"
                    ,
                    data: JSON.stringify
                    (formData),
                    success: function(response
                    ) {
                        alert
                        (response);
                        $(
                            "#changePasswordModal").modal("hide"
                        );
                    },
                    error: function(xhr
                    ) {
                        alert(xhr.responseText
                        );
                    }
                });
            });
        });
</script>

</body>
</html>